home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.03 Mar 90 / Debug CDEF Code / test_cdef_main.c < prev   
Encoding:
C/C++ Source or Header  |  1989-02-07  |  3.0 KB  |  135 lines  |  [TEXT/KAHL]

  1. /******** System includes ********/
  2. #include <Quickdraw.h>
  3. #include <ControlMgr.h>
  4. #include <MemoryMgr.h>
  5. #include <OSUtil.h>
  6. #include <WindowMgr.h>
  7. #include <EventMgr.h>
  8. /**********************************/
  9.  
  10. /******** defines ********/
  11. #define NULL    0L
  12. /**********************************/
  13.  
  14. /******** prototypes ********/
  15. void main( void ) ;
  16. void TestControl( void ) ;
  17. /**********************************/
  18.  
  19. /******** globals ********/
  20. Rect test_window_rect = { 40, 10, 300, 400 } ;
  21. Rect test_control_rect = { 10, 10, 34, 150 } ;
  22. WindowPtr window_ptr ;
  23. ControlHandle control_hdl ;
  24. ControlHandle control_hdl2 ;
  25. long tmp ;
  26. EventRecord event ;
  27. Point pt ;
  28. int part_code ;
  29. int last_part_code ;
  30. ControlHandle which_control ;
  31. RgnHandle clip ;
  32. Rect rect ;
  33. /**********************************/
  34.  
  35. void main( )
  36. {
  37.     /* Initialize the macintosh managers */
  38.     InitGraf( ( Ptr) &thePort ) ;
  39.     InitFonts( ) ;
  40.     InitWindows( ) ;
  41.     InitCursor( ) ;
  42.     InitMenus( ) ;
  43.     TEInit( ) ;
  44.     InitDialogs( 0L ) ;
  45.     MoreMasters( ) ;
  46.     MoreMasters( ) ;
  47.     MoreMasters( ) ;
  48.     MoreMasters( ) ;
  49.     MoreMasters( ) ;
  50.     MoreMasters( ) ;
  51.     MoreMasters( ) ;
  52.     MoreMasters( ) ;
  53.     FlushEvents( everyEvent, 0 ) ;
  54.  
  55.     /* Now call test control routine */
  56.     TestControl( ) ;
  57.     
  58.     return ;
  59. }
  60. void TestControl( )
  61. {
  62.     rect.top = 0 ;
  63.     rect.left = 0 ;
  64.     rect.right = 512 ;
  65.     rect.bottom = 382 ;
  66.     
  67.     /* Open the window */
  68.     window_ptr = NewWindow( NULL, &test_window_rect, "\ptest window", TRUE, 1, 
  69.                             (WindowPtr)-1L, FALSE, 0L ) ;
  70.                             
  71.     if( window_ptr == NULL ) return ;
  72.     
  73.     SetPort( window_ptr ) ;
  74.                             
  75.     /* Open the control */
  76.     control_hdl = NewControl( window_ptr, &test_control_rect, "\ptest control",
  77.                               TRUE, 0, 0, 0, 32, 0L ) ;
  78.     OffsetRect( &test_control_rect, 150, 50 ) ;
  79.     control_hdl2 = NewControl( window_ptr, &test_control_rect, "\ptest control",
  80.                               TRUE, 0, 0, 0, 32, 0L ) ;
  81.     
  82.     MoveTo( 110, 250 ) ;
  83.     DrawString( "\pHit any key to quit" ) ;
  84.     /* Now start miniature event loop */
  85.     while( TRUE ) {
  86.     
  87.         GetNextEvent( everyEvent, &event ) ;
  88.         
  89.         pt = event.where ;
  90.         
  91.         SetPort( window_ptr ) ;
  92.         
  93.         GlobalToLocal( &pt ) ;
  94.         
  95.         if( event.what == mouseDown ) {
  96.         
  97.             part_code = FindControl( pt, window_ptr, &which_control ) ;
  98.             
  99.             if( which_control == NULL ) {
  100.                 if( (**control_hdl).contrlHilite != 0 ) {
  101.                     HiliteControl( control_hdl, 0 ) ;
  102.                 }
  103.                 if( (**control_hdl2).contrlHilite != 0 ) {
  104.                     HiliteControl( control_hdl2, 0 ) ;
  105.                 }
  106.                 SysBeep( 5 ) ;
  107.             }else{
  108.                 part_code = TrackControl( which_control, pt, (ProcPtr)-1L ) ;
  109.                 HiliteControl( which_control, part_code ) ;
  110.                 if( which_control == control_hdl ) {
  111.                     if( (**control_hdl2).contrlHilite != 0 ) {
  112.                         HiliteControl( control_hdl2, 0 ) ;
  113.                     }
  114.                 }
  115.                 if( which_control == control_hdl2 ) {
  116.                     if( (**control_hdl).contrlHilite != 0 ) {
  117.                         HiliteControl( control_hdl, 0 ) ;
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.         if( event.what == keyDown ) {
  123.             break ;
  124.         }
  125.     }
  126.           
  127.     /* Close the control */
  128.     DisposeControl( control_hdl ) ;
  129.     DisposeControl( control_hdl2 ) ;
  130.  
  131.     /* Close the window */
  132.     DisposeWindow( window_ptr ) ;
  133.     return ;
  134. }
  135.